home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / role / ZIP_1_0.lha / src / mscio.c < prev    next >
C/C++ Source or Header  |  1992-10-13  |  7KB  |  416 lines

  1. /*
  2.  * mscio.c
  3.  *
  4.  * Microsoft C specific screen I/O routines for DOS.
  5.  *
  6.  * Mark Howell 28-Jul-1992 V1.0
  7.  *
  8.  */
  9.  
  10. #include "ztypes.h"
  11.  
  12. #include <conio.h>
  13. #include <graph.h>
  14.  
  15. #define BLUE 1
  16. #define WHITE 7
  17. #define BRIGHT 15
  18. #define RED 4
  19. #define GREEN 2
  20.  
  21. #ifdef __STDC__
  22. static void delete_char (void);
  23. #else
  24. static void delete_char ();
  25. #endif
  26.  
  27. static int cursor_saved = OFF;
  28. static struct rccoord rc;
  29.  
  30. #ifdef __STDC__
  31. void fatal (const char *s)
  32. #else
  33. void fatal (s)
  34. const char *s;
  35. #endif
  36. {
  37.  
  38.     reset_screen ();
  39.     printf ("\nFatal error: %s (PC = %lx)\n", s, pc);
  40.     exit (1);
  41.  
  42. }/* fatal */
  43.  
  44. #ifdef __STDC__
  45. void initialize_screen (void)
  46. #else
  47. void initialize_screen ()
  48. #endif
  49. {
  50.  
  51.     _setvideomode (_TEXTC80);
  52.     screen_rows = 25;
  53.     screen_cols = 80;
  54.     select_text_window ();
  55.     set_attribute (NORMAL);
  56.     clear_screen ();
  57.     move_cursor (screen_rows / 2, (screen_cols - sizeof ("The story is loading...")) / 2);
  58.     _outtext ("The story is loading...");
  59.  
  60. }/* initialize_screen */
  61.  
  62. #ifdef __STDC__
  63. void restart_screen (void)
  64. #else
  65. void restart_screen ()
  66. #endif
  67. {
  68.  
  69.     select_text_window ();
  70.     set_attribute (NORMAL);
  71.     clear_screen ();
  72.     move_cursor (screen_rows, 1);
  73.  
  74. }/* restart_screen */
  75.  
  76. #ifdef __STDC__
  77. void reset_screen (void)
  78. #else
  79. void reset_screen ()
  80. #endif
  81. {
  82.  
  83.     _setvideomode (_DEFAULTMODE);
  84.  
  85. }/* reset_screen */
  86.  
  87. #ifdef __STDC__
  88. void clear_screen (void)
  89. #else
  90. void clear_screen ()
  91. #endif
  92. {
  93.  
  94.     _clearscreen (_GCLEARSCREEN);
  95.  
  96. }/* clear_screen */
  97.  
  98. #ifdef __STDC__
  99. void create_status_window (void)
  100. #else
  101. void create_status_window ()
  102. #endif
  103. {
  104.  
  105.     if (window == STATUS_WINDOW)
  106.         select_status_window ();
  107.     else {
  108.         select_text_window ();
  109.         restore_cursor_position ();
  110.     }
  111.  
  112. }/* create_status_window */
  113.  
  114. #ifdef __STDC__
  115. void delete_status_window (void)
  116. #else
  117. void delete_status_window ()
  118. #endif
  119. {
  120.  
  121. }/* delete_status_window */
  122.  
  123. #ifdef __STDC__
  124. void select_status_window (void)
  125. #else
  126. void select_status_window ()
  127. #endif
  128. {
  129.  
  130.     save_cursor_position ();
  131.     _settextwindow (1, 1, status_size, screen_cols);
  132.     _wrapon (_GWRAPOFF);
  133.     _displaycursor (_GCURSOROFF);
  134.     _settextposition (1, 1);
  135.  
  136. }/* select_status_window */
  137.  
  138. #ifdef __STDC__
  139. void select_text_window (void)
  140. #else
  141. void select_text_window ()
  142. #endif
  143. {
  144.  
  145.     _settextwindow (status_size + 1, 1, screen_rows, screen_cols);
  146.     _wrapon (_GWRAPOFF);
  147.     _displaycursor (_GCURSORON);
  148.     _settextposition (screen_rows, 1);
  149.     restore_cursor_position ();
  150.  
  151. }/* select_text_window */
  152.  
  153. #ifdef __STDC__
  154. void clear_line (void)
  155. #else
  156. void clear_line ()
  157. #endif
  158. {
  159.     int i;
  160.     struct rccoord rcc;
  161.  
  162.     rcc = _gettextposition ();
  163.     for (i = rcc.col - 1; i < screen_cols; i++)
  164.         display_char (' ');
  165.     _settextposition (rcc.row, rcc.col);
  166.  
  167. }/* clear_line */
  168.  
  169. #ifdef __STDC__
  170. void clear_text_window (void)
  171. #else
  172. void clear_text_window ()
  173. #endif
  174. {
  175.  
  176.     set_attribute (NORMAL);
  177.     _clearscreen (_GWINDOW);
  178.  
  179. }/* clear_text_window */
  180.  
  181. #ifdef __STDC__
  182. void clear_status_window (void)
  183. #else
  184. void clear_status_window ()
  185. #endif
  186. {
  187.  
  188.     set_attribute (NORMAL);
  189.     _clearscreen (_GWINDOW);
  190.     move_cursor (1, 1);
  191.  
  192. }/* clear_status_window */
  193.  
  194. #ifdef __STDC__
  195. void move_cursor (int row, int col)
  196. #else
  197. void move_cursor (row, col)
  198. int row;
  199. int col;
  200. #endif
  201. {
  202.  
  203.     _settextposition (row, col);
  204.  
  205. }/* move_cursor */
  206.  
  207. #ifdef __STDC__
  208. void save_cursor_position (void)
  209. #else
  210. void save_cursor_position ()
  211. #endif
  212. {
  213.  
  214.     if (cursor_saved == OFF) {
  215.         rc = _gettextposition ();
  216.         cursor_saved = ON;
  217.     }
  218.  
  219. }/* save_cursor_position */
  220.  
  221. #ifdef __STDC__
  222. void restore_cursor_position (void)
  223. #else
  224. void restore_cursor_position ()
  225. #endif
  226. {
  227.  
  228.     if (cursor_saved == ON) {
  229.         _settextposition (rc.row, rc.col);
  230.         cursor_saved = OFF;
  231.     }
  232.  
  233. }/* restore_cursor_position */
  234.  
  235. #ifdef __STDC__
  236. void set_attribute (int attribute)
  237. #else
  238. void set_attribute (attribute)
  239. int attribute;
  240. #endif
  241. {
  242.  
  243.     switch (attribute) {
  244.         case REVERSE:    _setbkcolor (WHITE); _settextcolor (BLUE); break;
  245.         case BOLD:       _setbkcolor (BLUE);  _settextcolor (BRIGHT); break;
  246.         case BLINK:      _setbkcolor (BLUE);  _settextcolor (GREEN); break;
  247.         case UNDERSCORE: _setbkcolor (BLUE);  _settextcolor (RED); break;
  248.  
  249.         default:         _setbkcolor (BLUE);  _settextcolor (WHITE);
  250.     }
  251.  
  252. }/* set_attribute */
  253.  
  254. #ifdef __STDC__
  255. void display_char (int c)
  256. #else
  257. void display_char (c)
  258. int c;
  259. #endif
  260. {
  261.  
  262.     _outtext ((char *) &c);
  263.  
  264. }/* display_char */
  265.  
  266. #ifdef __STDC__
  267. void input_line (void)
  268. #else
  269. void input_line ()
  270. #endif
  271. {
  272.     char c, *cp;
  273.  
  274.     input[1] = 0;
  275.     cp = &input[2];
  276.     for ( ; ; ) {
  277.         c = input_character ();
  278.         if (c == '\x00e' || c == '\a')
  279.             output_char ('\007');
  280.         else if (c == '\r') {
  281.             *cp++ = c;
  282.             output_char (c);
  283.             scroll_line ();
  284.             return;
  285.         } else if (c == '\x07f' || c == '\b' || c == '\x00b') {
  286.             if (input[1] == 0)
  287.                 output_char ('\007');
  288.             else {
  289.                 input[1]--;
  290.                 cp--;
  291.                 delete_char ();
  292.             }
  293.         } else
  294.             if (input[1] == (input[0] - (char) 2))
  295.                 output_char ('\007');
  296.             else {
  297.                 input[1]++;
  298.                 *cp++ = c;
  299.                 output_char (c);
  300.             }
  301.     }
  302.  
  303. }/* input_line */
  304.  
  305. #ifdef __STDC__
  306. char input_character (void)
  307. #else
  308. char input_character ()
  309. #endif
  310. {
  311.     int c;
  312.  
  313.     for ( ; ; ) {
  314.         c = getch () & 0x7f;
  315.         if (c >= ' ' || c == '\b' || c == '\r')
  316.             return ((char) c);
  317.         c = getch ();
  318.         if (c == 'H')
  319.             return ('\x00e');
  320.         if (c == 'K')
  321.             return ('\x00b');
  322.         if (c == 'M')
  323.             return ('\x007');
  324.         if (c == 'P')
  325.             return ('\r');
  326.     }
  327.  
  328. }/* input_character */
  329.  
  330. #ifdef __STDC__
  331. static void delete_char (void)
  332. #else
  333. static void delete_char ()
  334. #endif
  335. {
  336.     struct rccoord rcc;
  337.  
  338.     rcc = _gettextposition ();
  339.     _settextposition (rcc.row, --rcc.col);
  340.     _outtext (" ");
  341.     _settextposition (rcc.row, rcc.col);
  342.  
  343. }/* delete_char */
  344.  
  345. #ifdef __STDC__
  346. void scroll_line (void)
  347. #else
  348. void scroll_line ()
  349. #endif
  350. {
  351.     int c = '\n';
  352.  
  353.     _outtext ((char *) &c);
  354.  
  355. }/* scroll_line */
  356.  
  357. /*
  358.  * fit_line
  359.  *
  360.  * This routine determines whether a line of text will still fit
  361.  * on the screen.
  362.  *
  363.  * line : Line of text to test.
  364.  * pos  : Length of text line (in characters).
  365.  * max  : Maximum number of characters to fit on the screen.
  366.  *
  367.  */
  368.  
  369. #ifdef __STDC__
  370. int fit_line (const char *line, int pos, int max)
  371. #else
  372. int fit_line (line, pos, max)
  373. const char *line;
  374. int pos;
  375. int max;
  376. #endif
  377. {
  378.  
  379.     return (pos < max);
  380.  
  381. }/* fit_line */
  382.  
  383. /*
  384.  * print_status
  385.  *
  386.  * Print the status line (type 3 games only).
  387.  *
  388.  * argv[0] : Location name
  389.  * argv[1] : Moves/Time
  390.  * argv[2] : Score
  391.  *
  392.  * Depending on how many arguments are passed to this routine
  393.  * it is to print the status line. The rendering attributes
  394.  * and the status line window will be have been activated
  395.  * when this routine is called. It is to return FALSE if it
  396.  * cannot render the status line in which case the interpreter
  397.  * will use display_char() to render it on its own.
  398.  *
  399.  * This routine has been provided in order to support
  400.  * proportional-spaced fonts.
  401.  *
  402.  */
  403.  
  404. #ifdef __STDC__
  405. int print_status (int argc, char *argv[])
  406. #else
  407. int print_status (argc, argv)
  408. int argc;
  409. char *argv[];
  410. #endif
  411. {
  412.  
  413.     return (FALSE);
  414.  
  415. }/* print_status */
  416.